import time, timeit
import socket

client = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
client.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, True)

client.connect(('127.0.0.1', 9090))

data = input("\033[;32msend(q to quit)> \033[;0m")
if data == 'q':
    client.close()
else:
    while len(data) > 0:
        client.send(data.encode('utf8'))
        data = client.recv(1024).decode('utf8')
        if len(data) == 0:
            break
        print('\033[;34mecho> \033[;0m', data)
        data = input('\033[;32msend> \033[;0m')
        if data == 'q':
            client.close()
            break
